package com.qdu.driver;
import com.qdu.bean.RentCarBean;
import com.qdu.bean.bikeWritable;
import com.qdu.mapper.CountByYearMapper;
import com.qdu.reducer.CountByYearReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class CountByYearDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
//        args = new String[] { "hdfs://node-1:9000/input1", "hdfs://node-1:9000/output" };
        args = new String[] { "D:/train.csv", "D:/output4" };
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(CountByYearDriver.class);

        job.setMapperClass(CountByYearMapper.class);
        job.setReducerClass(CountByYearReducer.class);

        job.setMapOutputKeyClass(bikeWritable.class);
        job.setMapOutputValueClass(RentCarBean.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(RentCarBean.class);

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
